﻿using System;
using AccessControl.Business;
using AccessControl.Sida.FingerPrintCollector.Form;
using DevExpress.XtraEditors;


namespace AccessControl.Sida.FingerPrintCollector.Login
{
	public static class LoginManager
	{
		#region Static Fields

		public static String CurrentUserName { get; set; }

		public static String CurrentPassword { get; set; }

		public static String CurrentFullName { get; set; }

		public static int CurrentUserID { get; set; }

		#endregion

		#region Static Methods

		public static Boolean Login(String userName, String password)
		{
			if (password == null)
				throw new ArgumentNullException("password");


			var groupUserBusiness = new GroupUserBusiness();
			var row = groupUserBusiness.SelectByUsername(userName);
			if (row == null)
				return false;
			if (row.Username.ToLower() == userName && row.Password == password)
			{
			    CurrentUserName = row.Username;
			    CurrentPassword = row.Password;
			    CurrentFullName = row.FullName;
				CurrentUserID = row.ID;
				new MainForm().Show();
			    return true;
			}
			return false;
		}

		#endregion
	}
}
